package com.buss;

import com.buss.mybatis.mapper.MyMapper;
import com.buss.storage.StorageProperties;
import com.buss.storage.StorageService;
import com.buss.util.OSProperties;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.HashMap;
import java.util.Map;

@Controller
@EnableWebMvc
@SpringBootApplication
@EnableConfigurationProperties(StorageProperties.class)
@MapperScan(basePackages = "com.buss.mybatis.mapper", markerInterface = MyMapper.class)
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@Bean
	CommandLineRunner init(StorageService storageService) {
		return (args) -> {
			// 清空删除上传文件目录
//            storageService.deleteAll();
			// 初始化（创建上传目录）
//            storageService.init();
		};
	}

	@Value("${location}")
	public String location;

	@RequestMapping("/")
	@ResponseBody
	String home() {
		return "upload service is ok";
	}
	@RequestMapping("/conf")
	@ResponseBody
	Map<String, Object> conf() {
		Map<String, Object> response = new HashMap<String,Object>();
		Map<String, Object> data = new HashMap<String,Object>();
		data.put("location", location);
//		data.put("repo", repo);
		data.put("repo", OSProperties.getUrlRepo());
		response.put("data", data);
		return response;
	}
}
